package com.sf.webside.config;

import com.sf.webside.dao.SysDictDao;
import com.sf.webside.entity.SysDictEntity;
import entity.StatusCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

/**
 * Created by tanjing on 2019/2/21.
 */
public class Global {
    @Value("${token.valid.time}")
    private int tokenValidTime;
    @Value("${request.token.key}")
    private String requestTokenKey;
    @Value("${image.absolute.path}")
    private String imageAbsolutePath;
    @Value("${image.relative.path}")
    private String imageRelativePath;
    @Value("${static.file.public.ip}")
    private String staticFilePublicIp;

    @Autowired
    private SysDictDao sysDictDao;
    /**
     * 获取字典value
     * @param type
     * @param lable
     * @return
     */
    public String getDictValue(String type,String lable){
        if(StringUtils.isBlank(type)||StringUtils.isBlank(lable)){
            return"";
        }
        SysDictEntity sysDictEntity=sysDictDao.findByTypeAndLabelAndDelFlag(type,lable,"0");
        if(sysDictEntity!=null){
            return sysDictEntity.getValue();
        }
        return "";
    }
    /**
     * 图片添加前缀
     * @return
     */
    public String imageAddPreFix(String image){
        if(StringUtils.isBlank(image)){
            return"";
        }
        return staticFilePublicIp+image;
    }
    /**
     * 图片添加前缀
     * @return
     */
    public String replaceImagePreFix(String image){
        if(StringUtils.isBlank(image)){
            return"";
        }
        String replaceAll=image.replaceAll(StatusCode.IP_PLACEHOLDER,staticFilePublicIp);
        return replaceAll;
    }


    public int getTokenValidTime() {
        return tokenValidTime;
    }

    public void setTokenValidTime(int tokenValidTime) {
        this.tokenValidTime = tokenValidTime;
    }

    public String getRequestTokenKey() {
        return requestTokenKey;
    }

    public void setRequestTokenKey(String requestTokenKey) {
        this.requestTokenKey = requestTokenKey;
    }

    public String getImageAbsolutePath() {
        return imageAbsolutePath;
    }

    public void setImageAbsolutePath(String imageAbsolutePath) {
        this.imageAbsolutePath = imageAbsolutePath;
    }

    public String getImageRelativePath() {
        return imageRelativePath;
    }

    public void setImageRelativePath(String imageRelativePath) {
        this.imageRelativePath = imageRelativePath;
    }

    public String getStaticFilePublicIp() {
        return staticFilePublicIp;
    }

    public void setStaticFilePublicIp(String staticFilePublicIp) {
        this.staticFilePublicIp = staticFilePublicIp;
    }

}
